<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\controller;
use think\Loader;
use think\Cache;

class Daily extends CrmController
{
    /**
     * dailyList
     */
    public function dailyList()
    {
        $menuname = "Daily List";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];     
        $this->assign("priv",$priv);

        // 模板输出
        return $this->fetch('dailyList');
    }


    /**
     * 获取日报列表资料
     * @return [type] [description]
     */
    public function dailyDataList()
    {
        // $users = Cache::get('users');
        $page = $_REQUEST["page"];
        $limit = $_REQUEST["limit"];
        //需先判断传值是否为空
        $where = "(1 ";
        $where .= empty($_REQUEST["createname"])?"":" AND createname = '".$_REQUEST["createname"]."'";
        $where .= empty($_REQUEST["view_user"])?"":" AND view_user like '%".$_REQUEST["view_user"]."%'";
        $where .= empty($_REQUEST["start_createtime"])?"":" AND createtime > '".$_REQUEST["start_createtime"]."'";
        $where .= empty($_REQUEST["end_createtime"])?"":" AND createtime < '".$_REQUEST["end_createtime"]."'";
        $where .= " )";
    
        $arrData = Loader::model('Daily')->getDailyData($where,$page,$limit);
        echo json_encode($arrData);
    }


    /**
     * 删除日报
     * @return [type] [description]
     */
    public function delDaily()
    {
        $id = $_REQUEST["id"];
        Loader::model('Daily')->delDaily($id);
    }


    /**
     * 日报详情
     * @return [json] [日报详细信息]
     */
    public function dailyDetails ()
    {
        $id = $_REQUEST["id"];
        $dailyInfo = Loader::model('Daily')->getDailyInfo($id);
        $this->assign('dailyInfo',$dailyInfo);
        return $this->fetch('dailyDetails');
    }


    /**
     * 加载日报评论列表
     * @return [json] [日报评论列表]
     */
    public function dailyCommentList ()
    {
        $id = $_REQUEST["id"];
        $dailyCommentInfo = Loader::model('Daily')->getDailyComment($id);
        echo json_encode($dailyCommentInfo);
    }

}